package com.shwread.android.qysw.activity;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.shwread.android.qysw10000182.R;
import com.shwread.httpsdk.util.Util;

import logic.bean.TicketInfo;
import logic.util.DateUtil;
import logic.util.MoneyUtil;
import logic.util.Utils;


public class OrderMenuTicketDetailActivity
        extends
        BaseBusinessActivity
        implements
        OnClickListener
{
	private Context  context;
	private View     view;
	private FrameLayout flView;
	private Button   btnBack, btnType;
	private TextView tvTitle;
	private TextView tvStore, tvMoney, tvType, tvHead, tvSaxNum, tvAddress, tvCreateTime, tvInvoiceTitle, tvInvoiceTime, tvCancelRemark;
	private TableRow trSaxNum, trCancelRemark;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.context = this;
		initView();
		initData();
		setListener();
	}
	
	private void initView() {
		view = View.inflate(context, R.layout.om_ticket_detail, null);
		setContentView(view);
		tvTitle = (TextView) view.findViewById(R.id.common_header_name);
		tvTitle.setText("发票详情");
		btnBack = (Button) view.findViewById(R.id.common_header_back);
		btnBack.setVisibility(View.VISIBLE);
		
		flView = (FrameLayout) view.findViewById(R.id.fl_om_ticket_recode_detail);
		tvStore = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_store);
		tvMoney = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_money);
		tvType = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_type);
		tvHead = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_head);
		trSaxNum = (TableRow) view.findViewById(R.id.tr_om_ticket_recode_list_item_sax_number);
		tvSaxNum = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_sax_number);
		tvAddress = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_address);
		tvCreateTime = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_create_time);
		tvInvoiceTitle = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_invoice_title);
		tvInvoiceTime = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_invoice_time);
		trCancelRemark = (TableRow) view.findViewById(R.id.tr_om_ticket_recode_list_item_cancelRemark);
		tvCancelRemark = (TextView) view.findViewById(R.id.tv_om_ticket_recode_list_item_cancelRemark);
		btnType = (Button) view.findViewById(R.id.btn_om_ticket_recode_list_item);
	}
	
	private void initData() {
		TicketInfo info = (TicketInfo) getIntent().getSerializableExtra("data");
		tvStore.setText(info.getShopName());
		tvMoney.setText(Utils.getOneMoneyFormat(MoneyUtil.divide(info.getPrice(), 100)) + "元");
		if (info.getBillType() == 1)
		{
			tvType.setText("个人");
			trSaxNum.setVisibility(View.GONE);
			flView.setBackgroundResource(R.drawable.om_ticket_recode_bg_person);
			btnType.setText("个人");
			btnType.setTextColor(Color.parseColor("#ff9600"));
			btnType.setBackgroundResource(R.drawable.om_ticket_record_person);
		}
		else
		{
			tvType.setText("企业");
			if (Util.isEmpty(info.getBillNo()))
			{
				trSaxNum.setVisibility(View.GONE);
			}
			else
			{
				trSaxNum.setVisibility(View.VISIBLE);
				tvSaxNum.setText(info.getBillNo());
			}
			flView.setBackgroundResource(R.drawable.om_ticket_recode_bg_enterprise);
			btnType.setText("企业");
			btnType.setTextColor(Color.parseColor("#57c6ff"));
			btnType.setBackgroundResource(R.drawable.book_ticket_main_unpressed);
		}
		tvHead.setText(info.getBillTop());
		tvAddress.setText(info.getDeliveryAddress().getProvinceName() + info.getDeliveryAddress().getCityName() + info.getDeliveryAddress().getAreaName() + info.getDeliveryAddress().getStreetName() + info.getDeliveryAddress().getDetailAddress());
		tvCreateTime.setText(DateUtil.getDate(info.getCreateTime()));
		if (info.getStatus() == 1)
		{
			tvInvoiceTitle.setText("发票状态：");
			tvInvoiceTime.setText("已申请");
			trCancelRemark.setVisibility(View.GONE);
		}
		else if (info.getStatus() == 2)
		{
			tvInvoiceTitle.setText("开票时间：");
			tvInvoiceTime.setText(DateUtil.getDate(info.getInvoiceTime()));
			trCancelRemark.setVisibility(View.GONE);
		}
		else
		{
			tvInvoiceTitle.setText("发票状态：");
			tvInvoiceTime.setText("已取消");
			trCancelRemark.setVisibility(View.VISIBLE);
			tvCancelRemark.setText(info.getCancelRemark());
		}
	}
	
	private void setListener() {
		btnBack.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.common_header_back:
				this.finish();
				break;
		}
	}
	
	@Override
	public Handler getUIHandler() {
		// TODO Auto-generated method stub
		return null;
	}
	
}
